import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

//改名字
public class MainH {
    public static int n;
    public static int[] arrB;
    public static List<List<Integer>> list = new ArrayList<>();
    public static List<Integer> path = new ArrayList<>();
    public static boolean[] flag;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        n = sc.nextInt();
        arrB = new int[n]; //B每天的等级
        for (int i = 0; i < n; i++) {
            arrB[i] = sc.nextInt();
        }

        flag = new boolean[n + 1];

        dfs(0);

        int ret = 0;
        for (List<Integer> listA : list) {
            int index = 0;
            int sumA = 0;
            int sumB = 0;
            for (int num : listA) {
                if (num != arrB[index]) {
                    if (num > arrB[index]) {
                        sumA += (index + 1);
                    } else {
                        sumB += (index + 1);
                    }
                }
                index++;
            }
            ret = Math.max(ret, sumA - sumB);
        }

        System.out.println(ret);

        sc.close();
    }

    public static void dfs(int pos) {
        //只统计叶子节点
        if (path.size() == n) {
            list.add(new ArrayList<>(path));
            return;
        }

        for (int i = 1; i < n + 1; i++) {
            if (!flag[i]) {
                path.add(i);
                flag[i] = true;
                dfs(i + 1);
                //回溯
                path.remove(path.size() - 1);
                flag[i] = false;
            }
        }
    }
}
